home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 141_01.zip / FGETSN.C < prev    next >
Text File  |  1993-06-01  |  1KB  |  47 lines

  1. /* 'FGETSN'  --  r p sarna  --  13 jan 1984  
  2.  
  3.    function to get a line of up to 'n' letters (or returns if hits
  4.    CR or 0x1A)   returns ERROR if error, TRUE otherwise 
  5. */
  6.  
  7. #define ERROR -1    /* General "on error" return value */
  8. #define SECSIZ 128    /* Sector size for CP/M read/write calls */
  9. #define TRUE 1        /* logical true constant */
  10. #define NSECTS 8    /* Number of sectors to buffer up in ram */
  11. #define BUFSIZ (NSECTS * SECSIZ + 7)    /* Don't touch this */
  12. struct _buf {                /* Or this...        */
  13.     int _fd;
  14.     int _nleft;
  15.     char *_nextp;
  16.     char _buff[NSECTS * SECSIZ];
  17.     char _flags;
  18. };
  19.  
  20. fgetsn(string, number_of_chars, filebuffer)
  21. char string[132];
  22. int number_of_chars;
  23. struct _buf *filebuffer;
  24. {
  25.     int i;
  26.     int ichr;
  27.     char chr;
  28.  
  29.     for (i = 0; i <= (number_of_chars - 1); i++) 
  30.     {
  31.         iµ ((ich≥ ╜ getc(filebuffer)⌐ =╜ ERROR || (ich≥ =╜ 0x1A⌐)
  32.         {
  33.             string[i] = '\0';
  34.             return( ERROR );
  35.         }
  36.         chr = ichr;
  37.         if ((chr == 0x0D) || (chr == 0x1A))
  38.         {
  39.             string[i] = '\0';
  40.             return( TRUE );
  41.         }
  42.     if ((chr != 0x0D) && (chr != 0x0A) && (chr != 0x1A)) string[i] = chr;
  43.     else i--;
  44.     }    
  45.     string[i + 1] = '\0';
  46.     return( TRUE );
  47. }